﻿<!DOCTYPE html>
<html>
<head>
    <title>HTML5报表应用WEB报表客户端打印与数据导出</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="Description" content="HTML5报表应用WEB报表客户端打印与数据导出。" />
    <meta name="Keywords" content="WEB报表,WEB打印,HTML5报表" />
    <link href="./libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <script src="./libs/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script src="./libs/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="./libs/grhtml5-6.7-min.js" type="text/javascript"></script>
    <script src="./libs/webapp/grwebapp.js" type="text/javascript"></script>

    <script language="javascript" type="text/javascript">
        var report = getStore({ name: 'report' }) || {}; //获取缓存中报表数据

        $(function () {     
            if (report) {
                //创建报表显示器，参数指定其在网页中的占位标签的ID，报表模板URL与报表数据URL不指定，而是在后面的AJAX操作中提供相关数据
                var reportViewer = window.rubylong.grhtml5.insertReportViewer( "report_holder" );
                reportViewer.reportPrepared = false; //指定报表生成需要加载报表模板
                reportViewer.dataPrepared = false; //指定报表生成需要加载报表数据
                //报表在模板与数据都载入后会自动生成
                reportViewer.loadReport(report.grf_json);
                reportViewer.loadData(JSON.stringify(report.obj_data));
                //*这句特别重要*：只有在WEB报表客户端程序后，才能进行WebSocket通讯
                //如果WEB报表客户端程序为开机自启动，以下调用应该去掉。更多说明请参考帮助“WEB报表(B/S报表)->WEB报表客户端->部署与安装”部分中与谷歌Chrome浏览器的相关说明
                webapp_urlprotocol_startup(); //启动WEB报表客户端程序，以便侦听接受 WebSocket 数据
            }
        });
        function webapp(args) { webapp_ws_run(args,report.grf_json, JSON.stringify(report.obj_data)) }
        function validatenull(val) {
            if (typeof val == 'boolean') {
                return false;
            }
            if (typeof val == 'number') {
                return false;
            }
            if (val instanceof Array) {
                if (val.length == 0) return true;
            } else if (val instanceof Object) {
                if (JSON.stringify(val) === '{}') return true;
            } else {
                if (val == 'null' || val == null || val == 'undefined' || val == undefined || val == '') return true;
                return false;
            }
            return false;
        }
        function getStore(params){
            let {
                name,
                debug
            } = params;
            name = 'rayd-' + name
            let obj = {},
                content;
            obj = window.sessionStorage.getItem(name);
            if (validatenull(obj)) obj = window.localStorage.getItem(name);
            if (validatenull(obj)) return;
            obj = JSON.parse(obj);
            if (debug) {
                return obj;
            }
            if (obj.dataType == 'string') {
                content = obj.content;
            } else if (obj.dataType == 'number') {
                content = Number(obj.content);
            } else if (obj.dataType == 'boolean') {
                content = eval(obj.content);
            } else if (obj.dataType == 'object') {
                content = obj.content;
            }
            return content;
        }
    </script>

    <style type="text/css">
        #toolbar {
            display: block;
            position: fixed;
            width: 100%;
            height: 40px;
            margin: 0;
            padding: 4px 4px;
            border: solid 1px;
            background-color: #fae3e3;
        }

        #report_holder {
            padding-top: 40px;
        }

        .rdock {
            position:absolute;
            right:8px;
        }
    </style>
</head>
<body>
    <div id="toolbar" class="row">
        <a class="btn btn-sm btn-primary" role="button" href='javascript:webapp({});'>打印预览</a>
        <a class="btn btn-sm btn-primary" role="button" href='javascript:webapp({"type":"print"});'>打印...</a>
        <a class="btn btn-sm btn-primary" role="button" href='javascript:webapp({"type":"print","showOptionDlg":"false"});'>直接打印</a>

        <a class="btn btn-sm btn-primary" role="button" href='javascript:webapp({"type":"pdf"});'>导出PDF</a>
        <a class="btn btn-sm btn-primary" role="button" href='javascript:webapp({"type":"xls"});'>导出Excel</a>
        <div class="btn-group btn-group-sm">
            <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">数据导出<span class="caret"></span></button>
            <ul class="dropdown-menu" role="menu">
                <li><a href='javascript:webapp({"type":"pdf"});'>PDF</a></li>
                <li><a href='javascript:webapp({"type":"xls"});'>Excel</a></li>
                <li><a href='javascript:webapp({"type":"rtf"});'>RTF</a></li>
                <li><a href='javascript:webapp({"type":"csv"});'>CSV</a></li>
                <li><a href='javascript:webapp({"type":"txt"});'>文本</a></li>
                <li><a href='javascript:webapp({"type":"img"});'>图像</a></li>
            </ul>
        </div>

        <a class="btn btn-sm btn-primary" role="button" href='javascript:webapp({"type":"grd"});'>生成报表文档</a>

        <a class="btn btn-sm btn-primary rdock" role="button" href="webapp-about.htm" target="_blank">执行任务无响应帮助</a>
    </div>

    <div id="report_holder">
        
    </div>
</body>
</html>